﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


    /// <summary>
    /// JsUtil 的摘要说明
    /// </summary>
    public class JsUtil
    {
        public JsUtil()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //

        }

        public static string MakeErrorAlertMessage(string errMsg)
        {
            string ErrorAlertMessageFormat = "<script language = javascript>alert('数据保存失败！{0}');</script>";
            return string.Format(ErrorAlertMessageFormat, errMsg);
        }

        private static string ScriptBegin = "<script language=\"JavaScript\">";
        private static string ScriptEnd = "</script>";

        public static void ConfirmMessageBox(Page page,string PageTarget, string Content)
        {
            string ConfirmContent = "var retValue=window.alert('" + Content + "');" + "if(retValue){window.location='" + PageTarget + "';}";

            ConfirmContent = ScriptBegin + ConfirmContent + ScriptEnd;


            if ( page.ClientScript.IsStartupScriptRegistered("confirm") != true)
            {
                page.ClientScript.RegisterStartupScript(page.GetType(),"confirm", ConfirmContent);
                
            }
            //Response.Write(strScript);
        }

        public static void MessageBox(Page page,string Content)
        {
            string ConfirmContent = "var retValue=window.alert('" + Content + "');";

            ConfirmContent = ScriptBegin + ConfirmContent + ScriptEnd;

            Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler;
            if (page.ClientScript.IsStartupScriptRegistered("alert") != true)
            {
                page.ClientScript.RegisterStartupScript(page.GetType(), "alert", ConfirmContent);
            }
            //Response.Write(strScript);
        }

    }
